<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="${staticServer}/inc/style/main.css" />
<link rel="stylesheet" href="${staticServer}/inc/style/page.css" />
<link rel="stylesheet" href="${staticServer}/css/work_today.css" />
<link rel="stylesheet" href="${staticServer}/inc/style/date/datepicker.css" />
<link rel="stylesheet" href="${staticServer}/css/consultant_client_tracking.css" />
<link rel="stylesheet" href="${staticServer}/inc/style/date/datepicker.css" />
<link rel="stylesheet" href="${staticServer}/css/consultant_client.css" />
<link rel="stylesheet" href="${staticServer}/css/consultant_client_tracking.css" />
<link rel="stylesheet" href="${staticServer}/css/consultant_student_read.css" />
<script src="${staticServer}/inc/js/jquery.js"></script>
<script src="${staticServer}/inc/js/pageset.js"></script>
<script src="${staticServer}/inc/js/model_resp.js"></script>
<script src="${staticServer}/inc/js/datepicker.js"></script>
<script src="${staticServer}/inc/js/htmlfilter.js"></script>
<script src="${staticServer}/inc/js/submitter.js"></script>
<script src="${staticServer}/inc/js/tips.js"></script>
<style type="text/css">
#statelist label {
	display: block;
	float: left;
	width: 120px;
}
</style>
<script>
	$(function(){
		$("#type").val("${type}");
		$("#state").val("<#if clientImp??>${clientImp.state}</#if>");
		$("#phone").val("<#if clientImp??>${clientImp.phone}</#if>");
		$("#lianxi_name").val("<#if clientImp??>${clientImp.lianxi_name}</#if>");
		$("#color").val("<#if clientImp??>${clientImp.color}</#if>");
		$("#st_type").val("<#if clientImp??>${clientImp.st_type}</#if>");
		
		$("#state1").val("${state1}");
	});
	var remove_tracking = function(){
		var id = $("#traId").val();
		$("#__TRACKING_LIST"+id).hide();
	}
	function btnShow(obj){
		 var b = $(obj).siblings('.caption').parent().parent().find('p:not(:first)').visible();
		 var s = $(obj).siblings('.caption').parent().parent().parent().children();
		 var h = $(obj).siblings('.caption').parent();
		 var remind = $(obj).siblings('.caption').parent().parent().find('#remind').val();
		 var sh = null;
		 if(remind!=""){
			 sh = $(obj).siblings('.caption').parent().parent().parent().children().children();
		 }else{
			 sh = $(obj).siblings('.caption').parent().parent().parent().children().children().not("#re");
		 }
		 
		 if(b == false){
				 sh.show();
				 s.show();
		 }else{
			 	sh.hide();
			 	h.show();
		 }
	}

var getFollow = function(keyname,id){
	$("#traId").val(id);
	$.post("${contextPath}/index/get_client_follow.json", {
		"keyname":keyname
	}, function(ms) {
		var list = ms.list;
		var objHtml = "";
		$("#trackList"+id).val("");
		if(list!=null){
			var j=list.length+1;
			for(var i=0;i<list.length;i++){
				var state = "";
				if(list[i].state=="" || list[i].state==null){
					state = '<a class="stateitem caption">无变化</a>';
				}else{
					state = '<a class="stateitem">'+list[i].state+'</a>';
				}
				if(list[i].state2=="" || list[i].state2==null){
					state2 = '';
				}else{
					state2 = '<a class="stateitem">'+list[i].state2+'</a>';
				}
				if(list[i].state3=="" || list[i].state3==null){
					state3 = '';
				}else{
					state3 = '<a class="stateitem">'+list[i].state3+'</a>';
				}
				if(list[i].startTime != null){
					remind_date = list[i].startTime;
				}else{
					remind_date = "";
				}				
				objHtml += '<ul>'+
	            			'<li>'+
	            				'<p class="trackingtitle" style="display: block;">第 '+(--j)+' 次跟踪记录<em class="caption">（负责人：'+list[i].nickname+'　日期：'+list[i].createTime+'）</em><a class="btnHidden" onclick="btnShow(this)">点击展开</a></p>'+
	            				'<p class="trackingstate" style="display: none;"><b>客户状态</b><span>'+state+state2+state3+'</span></p>'+
	            				'<p style="display: none;"><b>备注情况</b></p>'+
	            				'<p style="display:none;" id="re" ><b>提醒时间</b><input readonly="readonly" style="margin-left:5px;" value="'+remind_date+'" class="DatePicker_Icon" type="text" name="remind" id="remind" size="15" value="" rel="DATE::Y-m-d" /></p>'+
	            				'<div class="content" style="display: none;">'+list[i].remark+'</div>'+
	            			'</li>'+
	            		'</ul>'
			}
			$("#trackList"+id).html('<a class="stress unit" onclick="remove_tracking()"> 点击隐藏跟踪记录 </a>'+objHtml);
			$("#__TRACKING_LIST"+id).show();
			
		}
		
	});
}
$(function(){
	//全选按钮 
	$("#allChecked").click(function(){
		if($(this).is(':checked')==true){
			$("#datas td input[type=checkbox]").prop("checked","true");
		}else{
			$("#datas td input[type=checkbox]").prop("checked",false);
		}
	});

});

var deleteClient = function(){
	var $obj = $("#datas td input[type=checkbox]:checked");
	if($obj.length == 0){
		alert("请至少选择一条记录");
		return ;
	}
	if(confirm("确定删除？删除后无法恢复。")){
		var ids = '';
		for(var i = 0;i<$obj.length;i++){
			if(i == $obj.length-1){
				ids += $($obj[i]).val();
			}else{
				ids += $($obj[i]).val()+",";
			}
		}
		var url = "${contextPath}/consu/consultant_delete.json";
    	$.post(url, {"ids":ids}, 
			function(ms) {
	 			if(ms.msg != null){
	 				if(ms.msg == "0"){
	 					alert("不是自己的资源，无法删除！");
	 				}else if(ms.msg == "1"){
	 					alert("删除成功!");
	 					setTimeout(function(){
	 						location.reload(); 
						},1200);
	 				}else if(ms.msg == "2"){
	 					alert("已分配资源不可删除!");
	 				}
	 				
	 			}else{
	 				alert("抱歉，系统忙");
	 			}
    	});
    };
}

var updateClient = function(){
	var $obj = $("#datas td input[type=checkbox]:checked");
	if($obj.length == 0){
		alert("请至少选择一条记录");
		return ;
	}
	if(confirm("确定标记？标记后无法恢复。")){
		var ids = '';
		for(var i = 0;i<$obj.length;i++){
			if(i == $obj.length-1){
				ids += $($obj[i]).val();
			}else{
				ids += $($obj[i]).val()+",";
			}
		}
		var url = "${contextPath}/consu/consultant_update.json";
    	$.post(url, {"ids":ids}, 
			function(ms) {
	 			if(ms.msg != null){
	 				if(ms.msg == "0"){
	 					alert("不是自己的资源，无法标记！");
	 				}else if(ms.msg == "1"){
	 					alert("标记成功!");
	 					setTimeout(function(){
	 						location.reload(); 
						},1200);
	 				}else if(ms.msg == "2"){
	 					alert("已分配资源不可标记!");
	 				}
	 				
	 			}else{
	 				alert("抱歉，系统忙");
	 			}
    	});
    };
}

var czhi = function(){
	$("#type").val("");
	$("#state").val("");
	$("#color").val("");
	$("#st_type").val("");
	$("#lianxi_name").val("");
	$("#phone").val("");
	window.location.href="${contextPath}/consu/consultant_import_list.htm?haiQx=${haiQx}";
}
//状态选择器
function state(stat){
	window.location.href="${contextPath}/consu/consultant_import_list.htm?stat="+stat+"&haiQx=${haiQx}&teacherName=${teacherName}&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}";
}
//已分配老师 选择器
function yfpteacher(teacherName){
	window.location.href="${contextPath}/consu/consultant_import_list.htm?teacherName="+teacherName+"&haiQx=${haiQx}&stat=${statez}&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}";
}
/**
* 查询
*/
function submit(){
	window.location.href="${contextPath}/consu/consultant_import_list.htm?type="+$("#type").val()+"&lianxi_name="+$("#lianxi_name").val()+"&phone="+$("#phone").val()
			+"&state="+$("#state").val()+"&tui_nickname="+$("#tui_nickname").val()+"&stat="+$("#statez").val()+"&color="+$("#color").val()+"&st_type="
			+$("#st_type").val()+"&stardate="+$("#stardate").val()+"&enddate="+$("#enddate").val()+"&haiQx=${haiQx}&teacherName=${teacherName}&state=${statez}";
}
</script>
</head>

<body>
<input type="hidden" id="keyname" value="">
<input type="hidden" id="traId" value="">
	<div id="home_link">
		<ul>
			<li></li>
			<li>&gt;</li>
			<li>资源汇总</li>
			<li>&gt;</li>
			<li class="current">网推资源分配</li>
		</ul>
	</div>
	<div id="container">
		<div id="title">红色表示重复资源，紫色表示无效资源，蓝色表示重复加无效资源。</div>
		<table class="form_table">
			<tr>
				<td>
					<div style="overflow: hidden;">
						<label><b>查询条件：</b></label>
						<select id="type">
							<option value="">类型不限</option>
							<#if type2??>
								<#list type2?split(",") as name>
									<#if name?? && name!="">
										<option value="${name}"><#if name=="lixianbao">离线宝<#elseif name=="02FAC12A4746">百度糯米团购<#elseif name=="frvmppoifgmb">今日头条广告<#elseif name=="4D189169D77E">百度信息流</#if></option>
									</#if>
								</#list>
							<#else>
								<#if sourcelist??>
									<#list sourcelist as list>
										<option value="${list.keyname}">${list.name}</option>
									</#list>
								</#if>
							</#if>
						</select>
						
						<select id="statez">
							<option value="">选择预约状态</option>
							<option value="已预约" <#if statez == "已预约">selected</#if> >已预约</option>
							<option value="已测评" <#if statez == "已测评">selected</#if> >已测评</option>
							<option value="已缴费" <#if statez == "已缴费">selected</#if> >已缴费</option>
							<option value="未出现" <#if statez == "未出现">selected</#if> >未出现</option>
							<option value="无">无</option>
						</select>
						<select id="state">
							<option value="">分配状态</option>
							<option value="0">未分配</option>
							<option value="1">已分配</option>
						</select>
						<select id="color">
							<option value="">全部资源</option>
							<option value="1">重复资源</option>
						</select>
						<select id="st_type">
							<option value="">全部资源</option>
							<option value="1">有效资源</option>
							<option value="2">无效资源</option>
						</select>
						<input type="text" id="lianxi_name" size="10" value="" placeholder="客户姓名" /> 
						<input type="text" id="phone" size="12" value="" placeholder="电话/QQ" />
						<input type="text" id="tui_nickname" size="10" value="" placeholder="推广老师" /><br/><br/>
						<input style="margin-left:70px;" type="text" id="stardate" size="13" rel="DATE::Y-m-d" value="${stardate}" readonly="readonly" class="DatePicker_Icon">
						<input type="text" id="enddate" size="13" rel="DATE::Y-m-d" value="${enddate}" readonly="readonly" class="DatePicker_Icon">
						<input type="button" value=" 查 询 " onclick="submit()" />
						<#if webutil.getCookieUser().usergroup!=9>
							<input title="清理自己填写或上传的错误数据" type="button" value=" 删除 " onclick="deleteClient()" />
						</#if>
						<input type="button" value=" 重置 " onclick="czhi()" />
						<input type="button" value=" 标记无效 " onclick="updateClient()" />
					</div>
				</td>
			</tr>
		</table>
		<table>
			<tr class="fields">
				<th><input name="" type="checkbox" value="" id="allChecked"></th>
				<th>登记<br/>老师</th>
				<th>
					<select style="margin-left:2px;" id="teacherName" onchange="yfpteacher(this.value)">
						<option value="">分配状态</option>
			            <option value="zhangna" <#if teacherName == "zhangna">selected</#if> >张娜</option>
			            <option value="duanxueyan" <#if teacherName == "duanxueyan">selected</#if> >段雪艳 </option>
			            <option value="renbeibei" <#if teacherName == "renbeibei">selected</#if> >任贝贝</option>
			            <option value="gaoxiang" <#if teacherName == "gaoxiang">selected</#if> >高祥</option>
			            <option value="huangjuan" <#if teacherName == "huangjuan">selected</#if> >黄娟</option>
			            <option value="zhangmeiyi" <#if teacherName == "zhangmeiyi">selected</#if> >张美亿</option>
			            <option value="zhuxiaolong" <#if teacherName == "zhuxiaolong">selected</#if> >朱小龙</option>
			            <option value="luojinping" <#if teacherName == "luojinping">selected</#if> >罗金萍</option>
			            <option value="xijingxia" <#if teacherName == "xijingxia">selected</#if> >奚静霞</option>
		            </select>
				</th>
				<th>客户<br/>姓名</th>
				<th>电话/QQ</th>
				<th>城市</th>
				<th>渠道</th>
				<th>推广<br/>老师</th>
				<th>接待<br/>老师</th>
				<th>获取资源日期</th>
				<th>上传日期</th>
				
				<#if webutil.getCookieUser().username!="admin">
				<#if haiQx??>
				<#else>
				<th><select style="margin-left:2px;" id="state1" onchange="state(this.value)">
						<option value="">状态</option>
			            <option value="已预约" <#if state_s == "已预约">selected</#if> >已预约</option>
			            <option value="已测评" <#if state_s == "已测评">selected</#if> >已测评</option>
			            <option value="已缴费" <#if state_s == "已缴费">selected</#if> >已缴费</option>
			            <option value="未出现" <#if state_s == "未出现">selected</#if> >未出现</option>
			             <option value="无" <#if state_s == "无">selected</#if> >无</option>
		            </select></th>
				<th>最新<br/>跟踪</th>
				<th>继续跟<br/>踪价值</th>
				</#if>
				</#if>
				<th>操作</th>
			</tr>
			
			<tbody id="datas">
			<#if list??>
				<#list list as list>
					<tr class="even_row" <#if list.color=="1" && list.st_type=="2">style="color:#30A8CF;"<#elseif list.color=="1">style="color:red;"<#elseif list.st_type=="2">style="color:#A65BC1;"</#if>>
						<td align="center"><input name="" type="checkbox" value="${list.id}"></td>
						<td align="center">${list.nickname}</td>
						<td align="center"><#if list.state=="1"><a onclick="getFollow('${list.keyname}','${list.id}')" class="btnSearchTracking">${list.to_nickname}<#else>未分配</#if></td>
						<td align="center">${list.lianxi_name}</td>
						<td align="center"><#if list.phone?? && list.phone!="">${list.phone?replace(".00","")}/</#if><#if list.qq?? && list.qq!="">${list.qq?replace(".00","")}</#if>/<#if list.weixin?? && list.weixin!="">${list.weixin?replace(".00","")}</#if></td>
						<td align="center">
						<#if list.city?? || list.city!="">
							${list.city}
						<#else>
							${list.province}&nbsp;${list.province_city}
						</#if>
						</td>
						<td align="center"><#if list.qudao??>${list.qudao}<#else>${list.sourcens}</#if> </td>
						<td align="center">${list.tui_nickname}</td>
						<td align="center"><#if list.jd_kefu??>${list.jd_kefu}</#if></td>
						<td align="center"><#if list.jl_time??>${list.jl_time?string("yyyy-MM-dd HH:mm:ss")}</#if></td>
						<td align="center"><#if list.create_time??>${list.create_time?string("yyyy-MM-dd HH:mm:ss")}</#if></td>
						
						<#if webutil.getCookieUser().username!="admin">
						<#if haiQx??>
						<#else>
						<td align="center">
						<input type="hidden" id="stat" value="<#if state??>${state}</#if>">
						<#assign states = "${list.states}">
						<#if states?contains(',')?string == true>
							<#list states?split(',') as sta>
								<p style="margin:2px 0 2px;">
								<a class="stateitem" onclick="state('${sta}')" rel="">${sta}</a>
								</p>
							</#list>
							<#elseif list.states??>
							<a class="stateitem" onclick="state('${list.states}')" rel="">${list.states}</a>
							<#else>
							无
						</#if>
						</div>
						</td>
						
						<td class="breakall"><div contenteditable="false" title="${list.fallow}"><#if list.fallow?length gt 5>${list.fallow?substring(0,5)}...<#else>${list.fallow}</#if></div><em class="caption" title="${list.newTime}">${list.newTime}</em></td>
						
						<td>
							<#if list.worth=="1">
								维持客情
							<#elseif list.worth=="2">
								长期跟踪
							<#elseif list.worth=="3">
								计划跟踪
							<#elseif list.worth=="4">
								随后回访跟踪
							<#elseif list.worth=="5">
								必须跟踪争取
							<#elseif list.worth=="6">
								已成交</br>
								实际金额：<span class="stress">${list.money}</span>
							</#if>
						</td>
						
						</#if>
						</#if>
						
						<td align="center">
						<#if haiQx?? && haiQx=="1">
							<a href="${contextPath}/consu/consultant_import_allot.htm?id=${list.id}&currPage=${currPage}" >分配</a>
						<#else>
						
						<#if webutil.getCookieUser().username=="he">
							<a href="${contextPath}/consu/consultant_import_add.htm?id=${list.id}&type=1" class="btnSearchTracking">编辑</a>
						<#else>
							<#if webutil.getCookieUser().nickname==list.nickname>
								<a href="${contextPath}/consu/consultant_import_add.htm?id=${list.id}&type=1" class="btnSearchTracking">编辑</a> 
							<#else>
								<a href="${contextPath}/consu/consultant_import_add.htm?id=${list.id}&type=2" class="btnSearchTracking">查看</a> 
							</#if>
							<#if webutil.getCookieUser().usergroup==9>
								<#if list.state=="1">
								 -<a href="#" >分配</a>
								 <#else>
								 -<a href="${contextPath}/consu/consultant_import_allot.htm?id=${list.id}&currPage=${currPage}" >分配</a>
								 </#if>
							</#if>
						</#if>
						
						</#if>
						</td>
						
					</tr>
	            <tr id="__TRACKING_LIST${list.id}" style="display:none">
	            	<td colspan="10" class="trackinglst" id="trackList${list.id}">
	            	</td>
	            </tr>
				</#list>
			</#if>
			</tbody>
		</table>
	</div>
	<div id="pager" style="width: 820px;">
	<ul id="pagination">
		<#if page??>
		<#if page.pagetotal?? && page.pagetotal!="0">
	<#assign pagetotal = page.pagetotal>
	<#else>
	<#assign pagetotal = 1>
	</#if>
			<#if page.currpage??>
	<#assign currpage = page.currpage>
	<#else>
	<#assign currpage = 1>
	</#if>
				<#if currpage==1 >
					<li class="previous-off">上一页</li>
					<#else>
					<li class="previous"><a href="${contextPath}/consu/consultant_import_list.htm?currPage=${currpage-1}&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}&teacherName=${teacherName}">上一页</a></li>
					</#if>
					
		<#if pagetotal<=11>
			<#list 1..pagetotal as index_up>  
	           <#if currpage==index_up > 
	           		<li class="current">${index_up}</li>
	           <#else>
	           		<li><a href="${contextPath}/consu/consultant_import_list.htm?currPage=${index_up}&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}&teacherName=${teacherName}">${index_up}</a></li>  
	           </#if>  
			</#list>  
		<#else>
			<#if currpage<=8 >
				<#list 1..9 as index_up>  
	           	<#if currpage==index_up >  
	            	<li class="current">${index_up}</li>
	           	<#else>  
	               <li><a href="${contextPath}/consu/consultant_import_list.htm?currPage=${index_up}&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}&teacherName=${teacherName}">${index_up}</a></li> 
	           	</#if>
	           	</#list>  
	           	<li>...</li>
	           	<li><a href="${contextPath}/consu/consultant_import_list.htm?currPage=${pagetotal}&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}&teacherName=${teacherName}">${pagetotal}</a></li>  
				
			<#elseif (currpage>= 9 && currpage<pagetotal-7)  >	
				<li><a href="${contextPath}/consu/consultant_import_list.htm?currPage=1&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}&teacherName=${teacherName}">1</a></li>  
				<li>...</li>
				<#list currpage-3..currpage+3 as index_up>  
	           	<#if currpage==index_up >  
	             <li class="current">${index_up}</li>
	           	<#else>  
	               <li><a href="${contextPath}/consu/consultant_import_list.htm?currPage=${index_up}&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}&teacherName=${teacherName}">${index_up}</a></li>  
	           	</#if>
	           	</#list>
				<li>...</li>
	           	<li><a href="${contextPath}/consu/consultant_import_list.htm?currPage=${pagetotal}&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}&teacherName=${teacherName}">${pagetotal}</a></li>   
			<#else>
				<li><a href="${contextPath}/consu/consultant_import_list.htm?currPage=1&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}&teacherName=${teacherName}">1</a></li> 
				<li>...</li>
				<#list pagetotal-8..pagetotal as index_up>  
	           	<#if currpage==index_up >  
	             <li class="current">${index_up}</li>
	           	<#else>  
	               <li><a href="${contextPath}/consu/consultant_import_list.htm?currPage=${index_up}&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}&teacherName=${teacherName}">${index_up}</a></li> 
	           	</#if>
				</#list>  
			</#if>
			
		</#if> 
		<#if currpage==pagetotal >
		 	<li class="previous-off">下一页</li>
		<#else>
			<li class="previous"><a href="${contextPath}/consu/consultant_import_list.htm?currPage=${currpage+1}&type=${type}&state=${clientImp.state}&color=${clientImp.color}&st_type=${clientImp.st_type}&stat=${state1}&stardate=${stardate}&enddate=${enddate}&haiQx=${haiQx}&tui_nickname=${tui_nickname}&teacherName=${teacherName}">下一页</a></li>
		</#if>
		<li class="pageinfo">共${page.total}条记录</li>
	</#if>
	</ul>
	</div>
	<div class="emptyline"></div>
	
</body>
</html>